// 该ts文件用于定义category三级分类的小仓库
import { defineStore } from "pinia";
import { reqGetC1, reqGetC2, reqGetC3 } from "@/api/product/attr";
import type { categoryResonseData } from "@/api/product/attr/type";
import type { categoryState } from "./types/type";
const useCategoryStore = defineStore("category", {
  state: (): categoryState => {
    return {
      // 该字段用于存储一级分类的数据
      c1Arr: [],
      // 该字段用于存储一级分类的id
      c1Id: "",
      c2Arr: [],
      c2Id: "",
      c3Arr: [],
      c3Id: "",
    };
  },
  actions: {
    async getC1() {
      let res: categoryResonseData = await reqGetC1();
      if (res.code == 200) {
        this.c1Arr = res.data;
      }
    },
    async getC2() {
      let res: categoryResonseData = await reqGetC2(this.c1Id);
      if (res.code == 200) {
        this.c2Arr = res.data;
      }
    },
    async getC3() {
      let res: categoryResonseData = await reqGetC3(this.c2Id);
      if (res.code == 200) {
        this.c3Arr = res.data;
      }
    },
  },
  getters: {},
});
export default useCategoryStore;
